﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace DockSample
{
    class PrimitiveObjectDiagram : ObjectDiagram
    {
        //这些属性都不要保存到数据库
        
        

        public PrimitiveObjectDiagram(Point point, int width = 140, int height = 90)
            : base(point, width, height)
        {
            name = "PrimitiveObject";
        }
        public PrimitiveObjectDiagram(PrimitiveObjectDiagram diagram)
            : base(new Point(), diagram.width, diagram.height)
        {
            this.id = diagram.id;
            this.AttributeList = diagram.AttributeList;
            this.MethodList = diagram.MethodList;
        }
        //绘图函数
        //************************************************************************************
        /// <summary>
        /// 绘制图形对象本身
        /// 绘制图像对象多包含的文字
        /// 图形对象的大小随着文字量而改变
        /// </summary>
        /// <param name="g"></param>
        /// <param name="m"></param>
        public override void Drawing(Graphics g, DummyModelForm m)
        {
            Rectangle attributeRect = new Rectangle(upLeftpoint.X, upLeftpoint.Y, width, height / 3);
            Rectangle methodRect = new Rectangle(upLeftpoint.X, upLeftpoint.Y + height / 3, width, height / 3);
            Rectangle NFRRect = new Rectangle(upLeftpoint.X, upLeftpoint.Y + 2 * height / 3, width, height / 3);

            g.DrawRectangle(pen, attributeRect);
            g.DrawRectangle(pen, methodRect);
            g.DrawRectangle(pen, NFRRect);

            drawingAttributes(g, attributeRect);
            drawingMethods(g, methodRect);
            drawingNFR(g, NFRRect);
            
            base.Drawing(g, m);  
        }

        private void drawingAttributes(Graphics g, Rectangle attributeRect)
        {
            StringBuilder attrShowString = new StringBuilder();
            foreach (Attribute attr in AttributeList)
            {
                attrShowString.AppendLine(attr.getShowString());
            }
            g.DrawString(attrShowString.ToString(), drawFont, drawBrush, attributeRect);
        }

        private void drawingMethods(Graphics g, Rectangle methodRect)
        {
            StringBuilder methodShowString = new StringBuilder();
            foreach (Method method in MethodList)
            {
                methodShowString.AppendLine(method.getShowString());
            }
            g.DrawString(methodShowString.ToString(), drawFont, drawBrush, methodRect);
        }

        private void drawingNFR(Graphics g, Rectangle methodRect)
        {
            StringBuilder NFRShowString = new StringBuilder();
            if (ObjectNFRList.Count != 0)
            {
                NFRShowString.AppendLine("O_" + name + ":[" + getNFRListString(ObjectNFRList) + "]");
            }

            foreach (Attribute attr in AttributeList)
            {
                if (attr.AttributeNFRList.Count != 0)
                {
                    NFRShowString.AppendLine("A_" + attr.AttributeName + ":[" + getNFRListString(attr.AttributeNFRList) + "]");
                }
            }

            foreach (Method method in MethodList)
            {
                if (method.MethodNFRList.Count != 0)
                {
                    NFRShowString.AppendLine("M_" + method.MethodName + ":[" + getNFRListString(method.MethodNFRList) + "]");
                }
            }

            g.DrawString(NFRShowString.ToString(), drawFont, drawBrush, methodRect);
        }

    }
}
